<template>
	<!-- 成就 -->
	<view>
		<!-- 顶部区域 -->
		<view class="topmain">
			<image src="/static/images//oneImage/detailback.png" class="topmainbg"></image>
			<view class="topnav">
				<view class="userinfo">
					<navigator open-type="navigateBack">
						<image src="/static/images/blindbox/back.png"></image>
					</navigator>
				</view>
				<view class="info">
					<overlay title="活动规则" :content="ruleInfo" ref="overlay" />
					<view class="info_center">
						<view class="info_center_title">开盒领心愿币</view>
						<view class="info_center_text">最高可领666心愿币</view>
					</view>
					<view class="info_right">
						<view class="tool" @click="showRule">活动规则</view>
						<navigator class="tool" url="/pages/blindbox/rewardrecord">奖励记录</navigator>
					</view>
				</view>
				<view class="mainpic">
					<image src="/static/images/blindbox/box.png" class="mainpic_img"></image>
				</view>
				<view class="weeknum">本周当前累计次数: {{achievementInfo.week_num || 0}}次</view>
				<view class="openbox">
					<view class="openbox_item1">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.first_box != 2"></image>
							<text v-if="achievementInfo.first_box != 2">{{boxInfo.first_box || 0}}~{{boxInfo.first_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.first_box != 2" class="openbox_img" @click="openBox('first_box',achievementInfo.first_box)"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.first_box_num || 0}}次</text>
					</view>
					<view class="openbox_item2">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.first_box == 2 && achievementInfo.second_box != 2"></image>
							<text v-if="achievementInfo.first_box == 2 && achievementInfo.second_box != 2">{{boxInfo.second_box || 0}}~{{boxInfo.second_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.first_box == 2 && achievementInfo.second_box != 2" class="openbox_img" @click="openBox('second_box',achievementInfo.second_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.first_box != 2 && achievementInfo.second_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.second_box_num || 0}}次</text>
					</view>
					<view class="openbox_item3">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.second_box == 2 && achievementInfo.third_box != 2"></image>
							<text v-if="achievementInfo.second_box == 2 && achievementInfo.third_box != 2">{{boxInfo.third_box || 0}}~{{boxInfo.third_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.second_box == 2 && achievementInfo.third_box != 2" class="openbox_img" @click="openBox('third_box',achievementInfo.third_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.second_box != 2 && achievementInfo.third_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.third_box_num || 0}}次</text>
					</view>
					<view class="openbox_item4">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.third_box == 2 && achievementInfo.four_box != 2"></image>
							<text v-if="achievementInfo.third_box == 2 && achievementInfo.four_box != 2">{{boxInfo.four_box || 0}}~{{boxInfo.four_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.third_box == 2 && achievementInfo.four_box != 2" class="openbox_img" @click="openBox('four_box',achievementInfo.four_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.third_box != 2 && achievementInfo.four_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.four_box_num || 0}}次</text>
					</view>
					<view class="openbox_item5">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.four_box == 2 && achievementInfo.five_box != 2"></image>
							<text v-if="achievementInfo.four_box == 2 && achievementInfo.five_box != 2">{{boxInfo.five_box || 0}}~{{boxInfo.five_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.four_box == 2 && achievementInfo.five_box != 2" class="openbox_img" @click="openBox('five_box',achievementInfo.five_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.four_box != 2 && achievementInfo.five_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.five_box_num || 0}}次</text>
					</view>
					<view class="openbox_item6">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.five_box == 2 && achievementInfo.six_box != 2"></image>
							<text v-if="achievementInfo.five_box == 2 && achievementInfo.six_box != 2">{{boxInfo.six_box || 0}}~{{boxInfo.six_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.five_box == 2 && achievementInfo.six_box != 2" class="openbox_img" @click="openBox('six_box',achievementInfo.six_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.five_box != 2 && achievementInfo.six_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.six_box_num || 0}}次</text>
					</view>
					<view class="openbox_item7">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.six_box == 2 && achievementInfo.seven_box != 2"></image>
							<text v-if="achievementInfo.six_box == 2 && achievementInfo.seven_box != 2">{{boxInfo.seven_box || 0}}~{{boxInfo.seven_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.six_box == 2 && achievementInfo.seven_box != 2" class="openbox_img" @click="openBox('seven_box',achievementInfo.seven_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.six_box!== 2 && achievementInfo.seven_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.seven_box_num || 0}}次</text>
					</view>
					<view class="openbox_item8">
						<view class="openbox_tip">
							<image src="/static/images/blindbox/cjnengliang.png" v-if="achievementInfo.seven_box == 2 && achievementInfo.eight_box != 2"></image>
							<text v-if="achievementInfo.seven_box == 2 && achievementInfo.eight_box != 2">{{boxInfo.eight_box || 0}}~{{boxInfo.eight_box_end || 0}} 心愿币</text>
						</view>
						<image src="/static/images/blindbox/cjbox.png" v-if="achievementInfo.seven_box == 2 && achievementInfo.eight_box != 2" class="openbox_img" @click="openBox('eight_box',achievementInfo.eight_box)"></image>
						<image src="/static/images/blindbox/cjbox.png" v-else-if="achievementInfo.seven_box != 2 && achievementInfo.eight_box != 2" class="openbox_img"></image>
						<image src="/static/images/blindbox/opencjbox.png" v-else class="openbox_img"></image>
						<text class="openbox_text">开盒{{boxInfo.eight_box_num || 0}}次</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 可开出商品 -->
		<view class="main" v-if="blindboxList.length>0">
			<!-- 推荐盲盒 -->
			<view class="like">精选盲盒</view>
			<!-- 推荐盲盒 -->
			<view class="goodslist">
				<scroll-view scroll-x="true" style="white-space: nowrap;">
					<view class="goods" v-for="(item,index) in blindboxList" :key="index" @click="toDetail(item.id)">
						<image :src="item.cover_image" class="goods_img"></image>
						<view class="goods_tag">
							<view class="goods_tag_one" v-if="item.label_name.length > 0">
								<text>{{item.label_name[0]}}</text>
							</view>
							<view class="goods_tag_two" v-if="item.label_name.length > 1">
								<text>{{item.label_name[1]}}</text>
							</view>
							<view class="goods_tag_three" v-if="item.label_name.length > 2">
								<text>{{item.label_name[2]}}</text>
							</view>
						</view>
						<view class="goods_info">
							<view class="goods_info_title">{{item.name}}</view>
							<view class="goods_info_desc">{{item.activity_describe}}</view>
							<view class="goods_info_price">
								<view class="price" v-if="item.first_blood">￥ {{item.first_blood}}</view>
								<view class="sales">{{item.consume_num}}开盒</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<navigator class="openbtn" open-type="switchTab" url="/pages/blindbox/blindbox">去开盒</navigator>
			<overlay showSlot ref="reward">
				<view class="reward">
					<view class="reward_title">恭喜您</view>
					<view class="reward_content">
						获得<text>{{rewardInfo}}</text>心愿币！
					</view>
					<view class="reward_text">开启盲盒可获得更多成就</view>
					<view class="reward_text">请再接再厉!</view>
				</view>
			</overlay>
		</view>
	</view>
</template>

<script>
	import overlay from '@/components/overlay'
	export default {
		components:{
			overlay
		},
		data() {
			return {
				id:0,
				blindboxList:[],//推荐盲盒列表
				ruleInfo:'',//活动规则
				allowTap:true,//防误触
				rewardInfo:{},///成就开盒奖励信息
				boxInfo:{},///成就盒子奖励信息
				achievementInfo:{
					first_box:0,
					second_box:0,
					third_box:0,
					four_box:0,
					five_box:0,
					six_box:0,
					seven_box:0,
					eight_box:0
				}//成就盒子开盒状态信息
			}
		},
		onLoad() {
			uni.showLoading({
				title:'加载中...'
			})
			this.getAchievementindex();
			this.getAchievementrule();
		},
		methods: {
			//获取成就页面信息
			getAchievementindex(){
				this.$api.achievementindex().then(res=>{
					uni.hideLoading();
					this.achievementInfo = res.lottery;
					this.blindboxList = res.activity;
					this.blindboxList.forEach(item=>{
						if(item.label_name === null){
							item.label_name = [];
						}else{
							item.label_name = item.label_name.split(',');
						}
					})
					this.boxInfo = res.base_setting;
				})
			},
			toDetail(id){
				uni.navigateTo({
					url:`/pages/index/extractionBlindbox?id=${id}`
				})
			},
			//获取盲盒玩法规则
			getAchievementrule(){
				this.$api.achievementrule().then(res=>{
					this.ruleInfo = res;
				})
			},
			//显示盲盒玩法规则
			showRule(){
				this.$refs.overlay.show();
			},
			//开启成就宝箱
			openBox(get_box,status){
				//status 盒子状态 0 = 未满足条件，1 = 达到条件未领取，2 = 已领取
				if(status == 0){
					uni.showToast({
						title:'未满足开盒条件',
						icon:'none'
					})
					return
				}
				if(!this.allowTap) return
				this.allowTap = false;
				setTimeout(()=>{
					this.allowTap = true;
				},2000)
				this.$api.achievementget({
					id:this.achievementInfo.id,
					get_box
				}).then(res=>{
					this.rewardInfo = res;
					this.$refs.reward.show();
					this.getAchievementindex();
				})
			}
		}
	}
</script>

<style lang="scss">
.topmain{
	width: 750rpx;
	height: 1624rpx;
	position: relative;
	
	.topmainbg{
		@include img;
	}
}
.topnav{
	width: 750rpx;
	box-sizing: border-box;
	position: absolute;
	top: 0;
	padding-top: 180rpx;
	
	.userinfo{
		width: 750rpx;
		padding: 0 50rpx;
		@include between;
		position: fixed;
		z-index: 999;
		top: 106rpx;
		
		navigator{
			@include center;
			
			image {
				width: 50rpx;
				height: 50rpx;
			}
			text {
				font-size: 36rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FFFFFF;
				margin-left: 16rpx;
			}
		}
	}
	.info{
		position: relative;
		
		&_center{
			@include column-center;
			
			&_title{
				font-size: 40rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				text-shadow: 2rpx 2rpx 4rpx rgba(4, 4, 4, 0.5);
				transform: translateY(-20rpx);
			}
			&_text{
				width: 300rpx;
				height: 48rpx;
				background: linear-gradient(180deg, rgba(255, 255, 255, 0.14) 0%, rgba(100, 95, 95, 0.39) 50%, rgba(189, 189, 189, 0.3) 100%);
				box-shadow: 0 4rpx 8rpx 0 rgba(85, 55, 255, 0.31);
				border-radius: 39rpx;
				border: 2rpx solid;
				border-image: linear-gradient(90deg, rgba(0, 232, 255, 1), rgba(151, 95, 255, 1)) 2 2;
				clip-path: inset(0 round 39rpx);
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #520BFF;
				@include center;
			}
		}
		.info_right{
			position: absolute;
			top: -24rpx;
			right: 0;
		}
		.tool{
			width: 120rpx;
			height: 48rpx;
			background: rgba(255, 255, 255, 0.5);
			border-radius: 88rpx 0 0 88rpx;
			font-size: 22rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #666666;
			@include center;
			margin-bottom: 26rpx;
		}
	}
	.mainpic{
		text-align: center;
		margin-top: 58rpx;
		
		&_img{
			width: 412rpx;
			height: 412rpx;
		}
	}
	.weeknum{
		width: 360rpx;
		height: 60rpx;
		background: rgba(255, 255, 255, 0.7);
		box-shadow: 0 2rpx 4rpx 2rpx rgba(105, 22, 255, 0.29);
		border-radius: 48rpx;
		border: 2rpx solid #FFFFFF;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #520BFF;
		@include center;
		margin: 20rpx auto 0;
	}
	.openbox{
		position: relative;
		
		.openbox_tip{
			width: 240rpx;
			height: 74rpx;
			transform: translateY(20rpx);
			
			image{
				@include img;
			}
			text{
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #B557F7;
				position: absolute;
				top: 8rpx;
				left: 10rpx;
				width: 220rpx;
				@include one;
				text-align: center;
			}
		}
		.openbox_img{
			width: 98rpx;
			height: 98rpx;
		}
		.openbox_text{
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			text-shadow: 0 2rpx 2rpx rgba(0, 0, 0, 0.5);
		}
		.openbox_item1{
			@include column-center;
			position: absolute;
			top: 68rpx;
			left: 20rpx;
		}
		.openbox_item2{
			@include column-center;
			position: absolute;
			top: 84rpx;
			left: 262rpx;
		}
		.openbox_item3{
			@include column-center;
			position: absolute;
			top: 0rpx;
			left: 450rpx;
		}
		.openbox_item4{
			@include column-center;
			position: absolute;
			top: 290rpx;
			left: 188rpx;
		}
		.openbox_item5{
			@include column-center;
			position: absolute;
			top: 208rpx;
			left: 490rpx;
		}
		.openbox_item6{
			@include column-center;
			position: absolute;
			top: 412rpx;
			left: 22rpx;
		}
		.openbox_item7{
			@include column-center;
			position: absolute;
			top: 484rpx;
			left: 270rpx;
		}
		.openbox_item8{
			@include column-center;
			position: absolute;
			top: 412rpx;
			left: 474rpx;
		}
	}
}
.main{
	width: 750rpx;
	// background-image: url();
	background-size: cover;
	padding: 30rpx 0;
	box-sizing: border-box;
	margin-top: -10rpx;
	background-color: #3260c3; 
	
	.like{
		width: 264rpx;
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #FFFFFF;
		margin: 0 auto 30rpx;
		text-align: center;
		position: relative;
		
		&::before{
			content: '';
			width: 14rpx;
			height: 2rpx;
			background-color: #FFFFFF;
			position: absolute;
			left: 0rpx;
			top: 50%;
			transform: translateY(-50%);
		}
		&::after{
			content: '';
			width: 14rpx;
			height: 2rpx;
			background-color: #FFFFFF;
			position: absolute;
			right: 0rpx;
			top: 50%;
			transform: translateY(-50%);
		}
	}
}
.goodslist{
	display: flex;
	
	.goods{
		width: 336rpx;
		background-color: #F8F8F8;
		border-radius: 20rpx;
		margin-right: 16rpx;
		display: inline-block;
		
		&:first-child{
			margin-left: 24rpx;
		}
		
		&:last-child{
			margin-right: 24rpx;
		}
		
		&_img{
			width: 336rpx;
			height: 336rpx;
			border-radius: 20rpx 20rpx 0 0;
		}
		
		&_tag{
			@include between;
			margin-top: 22rpx;
			padding: 0 24rpx;
			height: 44rpx;
			
			&_one{
				width: 88rpx;
				height: 44rpx;
				background: linear-gradient(#FACA68, #FE240B);
				border-radius: 12rpx;
				@include center;
				
				text{
					font-size: 28rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FFFFFF;
					@include one;
				}
			}
			&_two{
				width: 88rpx;
				height: 44rpx;
				background: linear-gradient(#08E5FF, #9363FF);
				border-radius: 12rpx;
				@include center;
				
				text{
					font-size: 28rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FFFFFF;
					@include one;
				}
			}
			&_three{
				width: 88rpx;
				height: 44rpx;
				background: linear-gradient(#F767C4, #665EFF);
				border-radius: 12rpx;
				@include center;
				
				text{
					font-size: 28rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FFFFFF;
					@include one;
				}
			}
		}
		
		&_info{
			background-color: #FBFBFB;
			padding: 24rpx;
			border-radius: 0 0 20rpx 20rpx;
			
			&_title{
				width: 288rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #333333;
				padding: 0 9rpx;
				@include one;
			}
			&_desc{
				width: 288rpx;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				padding: 0 7rpx;
				margin-top: 14rpx;
				@include one;
			}
			&_price{
				height: 30rpx;
				@include between;
				padding: 0 9rpx 0 7rpx;
				margin-top: 17rpx;
				
				.price{
					font-size: 36rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FE3E46;
					width: 200rpx;
					@include one;
				}
				.sales{
					font-size: 24rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #666666;
					width: 120rpx;
					@include one;
					text-align: right;
				}
			}
		}
	}
}
.openbtn{
	width: 480rpx;
	height: 76rpx;
	background: linear-gradient(180deg, #FFBE00 0%, #FF1200 100%);
	box-shadow: 4rpx 4rpx 8rpx 0 #FF1400;
	border-radius: 36rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 500;
	color: #FFFFFF;
	@include center;
	margin: 68rpx auto;
}
.reward{
	width: 530rpx;
	height: 442rpx;
	background-image: url();
	background-size: cover;
	text-align: center;
	padding-top: 14rpx;
	
	&_title{
		font-size: 40rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #1A2294;
	}
	&_content{
		font-size: 48rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		margin: 78rpx auto 40rpx;
		
		text{
			font-size: 72rpx;
			margin: 0 10rpx;
		}
	}
	&_text{
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		margin-bottom: 40rpx;
	}
}
</style>
